
var ChangeStatusController = function($scope, $http, $modal){
	
	$http.defaults.headers.post["Content-Type"] = "application/json";
	var urlBase="http://localhost:8080/finalproject";
	
	$scope.getListUser = function(){
		$scope.resetError();
		$http.get(urlBase + '/changestatus/getlist').success(function(respone){
			$scope.listUsers = respone;
		}).error(function(){
			$scope.setError("Can't get List User");
		});
	}
	
	$scope.openInfo = function(id){
		$scope.resetError();
		$http.post(urlBase + '/changestatus/get/' + id).success(function(respone){
			var modalInstance = $modal.open({
                templateUrl: 'status.html',
                controller: $scope.ModalInstanceCtrl,
                resolve: {
                  user: function () {
                    return respone;
                  }
                }
           });
		}).error(function(){
			$scope.setError("Can't view user");
		});
	}
	
	$scope.activeUser = function(id){
		$scope.resetError();
		$http.post(urlBase + '/changestatus/active/' + id).success(function(){
			$scope.getListUser();
		}).error(function(){
			$scope.setError("Can't active user");
		});
	}
	
	$scope.disableUser = function(id){
		$scope.resetError();
		$http.post(urlBase + '/changestatus/disable/' + id).success(function(){
			$scope.getListUser();
		}).error(function(){
			$scope.setError("Can't active user");
		});
	}
	
	$scope.ModalInstanceCtrl = function ($scope, $modalInstance, user) {
		
          $scope.user = user;

          $scope.ok = function () {
            $modalInstance.dismiss('cancel');
          };
          
	}
	
	 $scope.setError = function(message){
         $scope.error = true;
         $scope.errorMessage = message;
	 }
	 
	 $scope.resetError = function(){
	         $scope.error = false;
	         $scope.errorMessage = '';
	 }
	 
	 $scope.getListUser();
}